package net.chathu.airgw.packets.chat 
{
	import net.chathu.airgw.Config;
	import net.chathu.airgw.model.JoinedRoomInfo;
	import net.chathu.airgw.model.Room;
	import net.chathu.airgw.model.User;
	import net.chathu.airgw.packets.gw.serverpackets.PartPacket;
	/**
	 * ...
	 * @author ze
	 */
	public class IRemRooms extends ChatPacket 
	{
		
		public function IRemRooms() 
		{
			
		}
		
		override public function execute():void
		{
			//>> irem|rooms/19/users|40324|1|id|40324
			
			var posA:int=(data[1]).indexOf('/',0) +1;
			var posB:int=(data[1]).indexOf('/', 7) ;
			var roomId:int=parseInt(data[1].substring(posA, posB));
			var userId:int = parseInt(data[2]);
			
			if (userId != sessionData.chatData.userId)
			{
				//valaki kilepett egy szobabol, ahol mi is ott voltunk..
				var user:User = User(sessionData.chatData.users.getUser(userId));
				if (user)
				{
					var room:Room = sessionData.chatData.rooms.getRoom(roomId);
					var roomInfo:JoinedRoomInfo = sessionData.chatData.getJoinedRoomInfo(roomId);
					if (roomInfo && room)
					{
						//trace(user.name + " kilepett a(z) " + room.name + " szobabol");
						roomInfo.removeUser(userId);
						sendToClient(new PartPacket(user.userHost,room.name));
						//_session.SessionData().ChatData().getSubChannels().getChannel(channelid).delete(userid);
					} else {
						trace("Hianyzo room v. roomInfo, roomId: " + roomId);
					}
					
				} else {
					trace("Ismeretlen user lepett ki egy szobabol: " + userId);
				}
			} else {
				//kileptunk egy szobabol, de ezt mashol kezeljuk
			}
		}
		
	}

}